package com.hd.trans.share;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

public class AudioTimeFormatUtil {
    private AudioTimeFormatUtil() {
    }

    public static String formatMin(long second) {
        long mm = second / 1000 / 60;
        if(mm > 0){
            return mm + "分钟";
        }else {
            long ss = second / 1000;
            if(ss > 0){
                return ss + "秒钟";
            }
        }

        return "";
    }

    /**
     * @param second 秒
     * @return 00:00:00
     */
    public static String formatSecond(long second) {
        String hh = second / 3600 > 9 ? second / 3600 + "" : "0" + second / 3600;
        String mm = (second % 3600) / 60 > 9 ? (second % 3600) / 60 + "" : "0" + (second % 3600) / 60;
        String ss = (second % 3600) % 60 > 9 ? (second % 3600) % 60 + "" : "0" + (second % 3600) % 60;
        return hh + ":" + mm + ":" + ss;
    }

    /**
     * @param millionSecond 毫秒
     * @return 00:00:00
     */
    public static String formatMillionSecond(long millionSecond) {
        if (millionSecond <= 0) {
            return "00:00:00";
        } else {
            return formatSecond((long) (millionSecond / 1000f));
        }
    }

    /**
     * 不足1秒会认为是1s
     *
     * @param millionSecond 毫秒
     * @return 00:00:00
     */
    public static String formatDurationMillionSecond(long millionSecond) {
        if (millionSecond <= 0) {
            return "00:00:00";
        } else if (millionSecond < 1000) {
            return "00:00:01";
        } else {
            return formatSecond(millionSecond / 1000);
        }
    }

    /**
     * 范例：2019年12月1日 12：12
     *
     * @param millionSecond
     * @return
     */
    public static String formatCreateTime(long millionSecond) {
        return TimeUtils.getDateToString(millionSecond, "yyyy/MM/dd HH:mm");
    }

    /**
     * 范例：20210202142410
     *
     * @param millionSecond
     * @return
     */
    public static String formatCreateTime1(long millionSecond) {
        return TimeUtils.getDateToString(millionSecond, "yyyyMMddHHmmss");
    }

    /**
     * 范例：2019年12月1日
     *
     * @param millionSecond
     * @return
     */
    public static String formatCreateTime2(long millionSecond) {
        return TimeUtils.getDateToString(millionSecond, "yyyy/MM/dd");
    }

    /**
     * 范例：2019年12月1日
     *
     * @param millionSecond
     * @return
     */
    public static String formatCreateTime3(long millionSecond) {
        return TimeUtils.getDateToString(millionSecond, "MM/dd HH:mm");
    }

    /**
     * 范例：2019年12月1日
     *
     * @param millionSecond
     * @return
     */
    public static String formatCreateTime4(long millionSecond) {
        return TimeUtils.getDateToString(millionSecond, "MMddHHmmss");
    }
    /**
     * 范例：12-1
     *
     * @param millionSecond
     * @return
     */
    public static String formatCreateTime5(long millionSecond) {
        return TimeUtils.getDateToString(millionSecond, "MM-dd HH:mm");
    }
    /**
     * 范例：12-21 12：23：12.wma
     *
     * @param millionSecond
     * @return
     */
    public static String formatCreateFileName(long millionSecond) {
        return TimeUtils.getDateToString(millionSecond, "MMddHHmmssSSS");
    }


    /**
     * 2020-01-01
     *
     * @param second 秒
     * @return
     */
    public static String getDateToString(long second) {
        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        final Date date = new Date(TimeUnit.SECONDS.toMillis(second));
        return simpleDateFormat.format(date);
    }
}
